﻿<UserControl x:Class="VmroleAuthor.Views.WindowsRolesAndFeaturesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:dw="clr-namespace:VmroleAuthor.Views"
             xmlns:viewModels="clr-namespace:VmroleAuthor.ViewModels"
             mc:Ignorable="d" 
             d:DesignWidth="900">    
    <UserControl.Resources>
        <ResourceDictionary>           
            
            <Style x:Key="TreeViewItemStyle" TargetType="TreeViewItem">
                <Setter Property="IsExpanded" Value="True" />
                <Setter Property="IsSelected" Value="{Binding IsInitiallySelected, Mode=TwoWay}" />
                <Setter Property="KeyboardNavigation.AcceptsReturn" Value="True" />
                <Setter Property="dw:VirtualToggleButton.IsVirtualToggleButton" Value="True" />
                <Setter Property="dw:VirtualToggleButton.IsChecked" Value="{Binding IsChecked}" />
            </Style>
            

            <HierarchicalDataTemplate  x:Key="CheckBoxItemTemplate" ItemsSource="{Binding Children}"
                                        DataType="{x:Type viewModels:WindowsServerRoleOrFeatureViewModel}">
                <StackPanel Orientation="Horizontal">
                    <!-- These elements are bound to a WindowsServerRoleOrFeatureViewModel object. -->
                    <CheckBox Focusable="False"  IsChecked="{Binding IsChecked}"  VerticalAlignment="Center" />
                    <ContentPresenter Content="{Binding DisplayName, Mode=OneTime}" Margin="2,0" />
                </StackPanel>
            </HierarchicalDataTemplate>
        </ResourceDictionary>                   
    </UserControl.Resources>
    
    <Grid VerticalAlignment="Top">
        <Grid.RowDefinitions >
            <RowDefinition Height="6" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="30" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="30" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="6"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="6"/>
        </Grid.ColumnDefinitions>

        <Label  Grid.Row="1" Grid.Column="0" >Compatible OS</Label>
        <ListBox Grid.Row="1" Grid.Column="2"  ItemsSource="{Binding Path=CompatibleOperatingSystems}" SelectedItem="{Binding Path=SelectedCompatibleOperatingSystem}">
            <ListBox.ItemTemplate>
                <DataTemplate DataType="string">
                    <RadioButton  IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}},Path=IsSelected}">
                        <Grid>
                            <Grid.ColumnDefinitions>                                
                                <ColumnDefinition Width="2"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="2"/>                               
                            </Grid.ColumnDefinitions>
                            <TextBlock  Grid.Column="1" Text="{Binding }"/>                         
                        </Grid>
                    </RadioButton>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <Label  Grid.Row="3" Grid.Column="0" >Roles</Label>
        <TreeView Grid.Row="3" Grid.Column="2" 
                  x:Name="RoleTree"                
                  ItemContainerStyle="{StaticResource TreeViewItemStyle}" 
                  ItemsSource="{Binding Mode=OneWay, Path=WindowsServerRoleViewModels}" 
                  ItemTemplate="{StaticResource CheckBoxItemTemplate}" />

        <Label  Grid.Row="5" Grid.Column="0" >Features</Label>
        <TreeView Grid.Row="5" Grid.Column="2" 
                  x:Name="FeatureTree"      
                  ItemContainerStyle="{StaticResource TreeViewItemStyle}" 
                  ItemsSource="{Binding Mode=OneWay, Path=WindowsServerFeatureViewModels}" 
                  ItemTemplate="{StaticResource CheckBoxItemTemplate}" />

    </Grid>
</UserControl>
